;(function($,window){
    var chartfunction=new chartFun();
    chartfunction.loadingPage(function () {

        setHeight($('.right_bar'),$('.h-filter'),$('.filter-bottom'));
        /**
         * @method 参数获取
         * @param {String} name 柱状图名称
         * @param {Array} time 起始结束时间
         * @returns {Object} 参数对象
         * @desc 获取图表更新参数
         */
        function getParam(time){
            var time=time?time:($('#start').val()).split('~'),type=$('.radio input:checked').val(),
                titleType=$('#inputselect1').val();
            var timestart,timeend;
            var typeName=$('#divselect1 cite').text(),
                city=$('#inputselect2').val(),
                cityName=$('#divselect2 cite').text();
            timestart=time[0];
            timeend=time[1]?time[1]:'';
            var thisparam={
                titleType:titleType,//诉求类型
                titleTypeName:typeName,//诉求类型名称
                timeType:type,//时间类型 阶段则为null
                time:{//阶段时间
                    start:timestart,
                    end:timeend
                },
                city:city,//城市代码
                cityName:cityName//城市名称
            };
            return thisparam;
        }
        /**
         * @method 模块标题更新
         * @param {String} param 页面参数
         * @returns {null} 无
         * @desc 根据获取的参数更新模块的标题
         */
        function updataTitle(param){
            var timeArr={'01':'本月','02':'本季度','03':'本年'};
            //如果类型是全部
            var typetitle1,typetitle2,timeType,cityName=param.cityName;
            if(param.titleType=='00'){/*数据修改*/
                typetitle1='';
                typetitle2='全省';
            }else{
                typetitle1=param.titleTypeName+'类';
                typetitle2=param.titleTypeName+'类';
            }

            if(param.timeType){
                timeType=timeArr[param.timeType];
            }else{
                timeType='本阶段';
            }
            $('.timeType').text(timeType);
            $('.thistype').text(typetitle1);
            $('.thisarea').text(typetitle2);
            $('.thisCity').text(cityName);
        }

        /**
         * @method 更新图表和表格
         * @param {String} name 柱状图名称
         * @param {Array} time 起始结束时间
         * @returns {null} 无
         * @desc 更新所有图表和表格
         */
        function updataAll(time){
            var param=getParam(time);

            //模块标题更新
            updataTitle(param);

            if(pie1){
                pie1.clear();
            }

            //圆环图表切换，实际应用中切换数据即可
            if(param.titleType=='00'){/*数据修改*/
                pie1=chartfunction.echartPie2Init('pie1',pieData);
            }else{
                pie1=chartfunction.echartPie3Init('pie1',pieData1);
                chartfunction.interPie3Init(pie1,5000);
            }

            //折线图更新
            if(line1){
                line1.clear();
            }
            line1=chartfunction.echartLineInit('line1',lineData);
            chartfunction.IntervalIns(line1,5000);

            //柱状图更新并定时播放
            if(bar1){
                bar1.clear();
            }
            bar1=chartfunction.echartBarInit('bar1',barData);
            chartfunction.IntervalIns(bar1,5000);
        }

        var chartfunction=new chartFun();
        chartfunction.upadataTime('',1000);
        // 环数据
        var pieData={
            series:[{
                name:'诉求类型',
                data:[
                    {value:477000, name:'投诉（含举报）'},
                    {value:131000, name:'求助'},
                    {value:17000, name:'感谢（含建议）'},
                    {value:28000, name:'便民'}
                ]
            }]
        };
        //饼图+环数据
        var pieData1={
            series:[{
                data:[
                    {value:135462, name:'城乡建设',child:[
                            {name:'市政市容物业',  value:58085},
                            {name:'违章建筑',     value:31611},
                            {name:'住房与房地产',  value:18365},
                            {name:'其他',  value:27401}
                        ]},
                    {value:53420, name:'环境保护',child:[
                            {name:'其他环境保护',value:29069},
                            {name:'噪音',value:2264},
                            {name:'污染',value:1369},
                            {name:'其他',value:20781}
                        ]},

                    {value:25286, name:'交通运输',child:[
                            {name:'交通公共运输',value:17288},
                            {name:'交通建设管理',value:1923},
                            {name:'客货运输',    value: 693},
                            {name:'其他',    value: 5328}
                        ]},

                    {value:20563, name:'政法',child:[
                            {name:'交通安全',value:7172},
                            {name:'社会治安',value:3549},
                            {name:'警务督察',value:3523},
                            {name:'其他',    value: 6318}
                        ]},
                    {value:26195, name:'其他',child:[
                            {name:'社区管理',value:11943},
                            {name:'其他教育类',value:5375},
                            {name:'教育行政管理',value:3877},
                            {name:'其他',value:5000}
                        ]}
                ]
            }]
        };
        var pie1;
        //折线图数据
        var lineData={
            xAxis: [{
                data: ['省平台','福州','莆田','厦门','平潭','泉州','三明','南平','宁德','漳州','龙岩']
            }],
            yAxis:[{
                name: '数量（万)'
            }],
            series: [
                {
                    name:'本月办理总量',
                    data:[3000,2500,1900,2200,2600,2300,1700,1990,2100,1500,1600]
                },
                {
                    name:'上月办理总量',
                    data:[1400,2000,1400,1800,1800,1500,1500,1600,2000,1000,800]
                }
            ]};
        var line1;
        //柱状图数据
        var barData={
            xAxis: [{
                data: ['省平台 ','福州','厦门','泉州','莆田','龙岩','漳州','三明','平潭','宁德'],
            }],
            yAxis:[{
                name: '件数',
                unit: '件'
            }],
            series: [
                {
                    name:'城乡建设',
                    data:[300000,250000,90000,220000,190000,230000,110000,220000,190000,230000,110000]
                },
                {
                    name:'环境保护',
                    data:[120000,200000,50000,180000,110000,70000,40000,200000,50000,180000,110000]
                },
                {
                    name:'政法',
                    data:[80000,120000,50000,80000,150000,220000,20000,80000,150000,220000,20000]
                },
                {
                    name:'交通运输',
                    data:[80000,120000,50000,80000,150000,220000,2000,80000,150000,220000,20000]
                },
                {
                    name:'其他',
                    data:[80000,120000,50000,80000,150000,220000,20000,50000,80000,150000,200002]
                }
            ]};
        var bar1;



        //月，季度，年选项
        $('.radio input').on('change',function(e){
            if($(this).is(':checked')){
                $('.radio label').removeClass('on');
                $(this).parent().addClass('on');
            }else{
                $(this).parent().removeClass('on');
            }
            $('#start').val('');
            updataAll();
            e.stopPropagation();
        });

        //类型下拉 数据
        var selectData=[
            {name:'全部',value:'00'},
            {name:'感谢（含建议）',value:'01'},
            {name:'投诉（含举报）',value:'02'},
            {name:'求助',value:'03'}
        ];
        var divselect=new divSelectFunction();
        divselect.init("#divselect1","#inputselect1",selectData,function(){
            updataAll();
        });

        //省市下拉初始化 数据
        var selectData2=[
            {name:'全省',value:'00'},
            {name:'省平台',value:'01'},
            {name:'福州市',value:'04'},
            {name:'省平台',value:'05'},
            {name:'莆田市',value:'06'},
            {name:'龙岩市',value:'07'},
            {name:'厦门市',value:'08'},
            {name:'漳州市',value:'09'},
            {name:'南平市',value:'10'},
            {name:'三明市',value:'11'},
            {name:'宁德市',value:'12'},
            {name:'泉州市',value:'13'},
            {name:'平潭',value:'14'}
        ];
        divselect.init("#divselect2","#inputselect2",selectData2,function(){
            updataAll();
        });

        //时间选择
        var start=laydate.render({
            elem: '#start', //指定元素
            type:'month',
            format: 'yyyy-MM',
            range:'~',
            max:0,
            theme: '#2d65ab',
            //value: new Date(),
            done:function(value, beginDate, endDate){
                $('.radio input').prop('checked',false);
                $('.radio label').removeClass('on');
                var beginM=(beginDate.month).toString().length==2?beginDate.month:'0'+beginDate.month;
                var endM=(endDate.month).toString().length==2?endDate.month:'0'+endDate.month;

                var time=[beginDate.year+'-'+beginM,endDate.year+'-'+endM];

                updataAll(time);
            }
        });

        //图表更新
        updataAll();

        //改变屏幕时
        $(window).resize(function(){
            setHeight($('.right_bar'),$('.h-filter'),$('.filter-bottom'));
            line1.resize();
            pie1.resize();
            bar1.resize();
        });
    },800);

})(jQuery,window);

